package control;

import java.io.IOException;
import java.util.Date;
import java.util.TimerTask;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;

public class MyTimerTask extends TimerTask {
	static int NO=0;
	ControlClient client;
	int rate=50;
	int no;
	public MyTimerTask(ControlClient client,int rate){
		this.client=client;
		no=NO++;
		this.rate=rate;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			if(rate==0){
				System.out.println("lowest!!");
				return;
			}
			client.setRate(rate);
			System.out.println(no+":"+new Date()+":\t"+client.connector.getConnectionId()+" will set rate to :"+rate);
		} catch (MalformedObjectNameException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AttributeNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstanceNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidAttributeValueException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NullPointerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MBeanException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ReflectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}
